import chalk from "chalk"
import ora from 'ora'
import process from "child_process"
import { log } from "../utils/log"

const spinner = ora({
    text: 'hcreate-cli is updating...',
    color: 'green',
    spinner: {
      interval: 300,
      frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].map(item => chalk.green(item)),
    },
  })
export async function update() {
    spinner.start()
    process.exec('npm install hcreate-cli@latest -g --force', (err) => {
        spinner.stop()
        if (!err) {
            log.success(chalk.green('hcreate-cli is updated'))
        } else {
            log.error(chalk.red('hcreate-cli update failed'))
        }
    })
}